unit uForm_dialog_input_vec3;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  Tfrmdicalog_input_vec3 = class(TForm)
    edt_x: TEdit;
    edt_y: TEdit;
    edt_z: TEdit;
    btn_ok: TButton;
    btn_cancel: TButton;
    lbl1: TLabel;
    procedure edt_xKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure edt_yKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure edt_zKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormShow(Sender: TObject);
    procedure btn_okClick(Sender: TObject);
    procedure btn_cancelClick(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure btn_okKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure btn_cancelKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure edt_yKeyPress(Sender: TObject; var Key: Char);
    procedure edt_zKeyPress(Sender: TObject; var Key: Char);
    procedure edt_xKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
    function CharMayBeFloat(ch : AnsiChar) :Boolean;
  public
    { Public declarations }
    m_result :Boolean;

    function ExecuteDialog(const caption :PAnsiChar;
      x :PSingle; y :PSingle; z :PSingle   ) :boolean;

  end;

var
  frmdicalog_input_vec3: Tfrmdicalog_input_vec3 = nil;

implementation

{$R *.dfm}

function Tfrmdicalog_input_vec3.ExecuteDialog(const caption :PAnsiChar;
      x :PSingle; y :PSingle; z :PSingle   ) :boolean;
begin
   Result := false;
    m_result := false;

    self.edt_x.Text := SysUtils.FloatToStr(x^);
    self.edt_y.Text := SysUtils.FloatToStr(y^);
    self.edt_z.Text := SysUtils.FloatToStr(z^);

    ShowModal;
   Result := m_result;
   if Result = False then
    begin
      Exit;
    end;

   x^ := SysUtils.StrToFloat(self.edt_x.text);
   y^ := SysUtils.StrToFloat(self.edt_y.text);
   z^ := SysUtils.StrToFloat(self.edt_z.text);

   result := true;
end;

procedure Tfrmdicalog_input_vec3.edt_xKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);

begin
    if Key = 27 then // ESC
     begin
       Close();
     end;

    if Key = 40 then // down
     begin
       edt_y.SetFocus();
     end;



end;

procedure Tfrmdicalog_input_vec3.edt_yKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);

begin
   if Key = 27 then // ESC
     begin
       Close();
     end;

    if Key = 40 then // down
     begin
       edt_z.SetFocus();
     end;

    if Key = 38 then // up
      begin
        edt_x.SetFocus;
      end;

end;

procedure Tfrmdicalog_input_vec3.edt_zKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
    if Key = 27 then // ESC
     begin
       Close();
     end;


    if Key = 40 then // down
     begin
       self.btn_ok.SetFocus;
     end;

    if Key = 38 then // up
      begin
        edt_y.SetFocus;
      end;


end;

procedure Tfrmdicalog_input_vec3.FormShow(Sender: TObject);
begin
  m_result := false;
end;

procedure Tfrmdicalog_input_vec3.btn_okClick(Sender: TObject);
begin
 m_result := True;
 Close();
end;

procedure Tfrmdicalog_input_vec3.btn_cancelClick(Sender: TObject);
begin
 m_result := false;
 Close();
end;

procedure Tfrmdicalog_input_vec3.FormKeyPress(Sender: TObject; var Key: Char);
begin
 //
end;

procedure Tfrmdicalog_input_vec3.btn_okKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
   if Key = 27 then // esc
    begin
      Close();
    end;
end;

procedure Tfrmdicalog_input_vec3.btn_cancelKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
   if Key = 27 then // esc
    begin
      Close();
    end;
end;

procedure Tfrmdicalog_input_vec3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if m_result = True then
    begin
 
    end;
end;

procedure Tfrmdicalog_input_vec3.edt_yKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
   begin
     m_result := True;
     Close();
   end;

  if not CharMayBeFloat( Key ) then
    begin
        Key := #0;
    end;

end;

procedure Tfrmdicalog_input_vec3.edt_zKeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key = #13 then
   begin
     m_result := True;
     Close();
   end;

   if not CharMayBeFloat( Key ) then
    begin
        Key := #0;
    end;


end;

procedure Tfrmdicalog_input_vec3.edt_xKeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key = #13 then
   begin
     m_result := True;
     Close();
   end;

   if not CharMayBeFloat( Key ) then
    begin
        Key := #0;
    end;

end;

function Tfrmdicalog_input_vec3.CharMayBeFloat(ch : AnsiChar) :Boolean;
begin
    result := True;
    if (ch >= '0') and (ch <= '9') then Exit;
    if ch = 'e' then Exit;
    if ch = '+' then Exit;
    if ch = '-' then Exit;
    if ch = '.' then Exit;



    result := false;
end;

end.
